package com.tongqu.configbean;

import com.tongqu.handlers.UserChannel;
import com.tongqu.handlers.WorkController;
import com.tongqu.protocol.TestCodec;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
@Slf4j
public class NettyChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Autowired
    WorkController forwardingTextHandler;
    @Autowired
    private UserChannel userChannel;


    LoggingHandler LOGGING_HANDLER = new LoggingHandler(LogLevel.INFO);


    @Override
    protected void initChannel(SocketChannel ch)  {

        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(LOGGING_HANDLER);
        pipeline.addLast("codec", new TestCodec());
        ch.pipeline().addLast(userChannel);
    }
}
